<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/2/7
 * Time: 18:12
 */
namespace app\api\common;
use think\Controller;
use think\Db;
use think\Exception;

class Shop extends Controller
{
    protected static $err_code = 0;

    /**
     *
     * @apiGroup Shop
     * @apiVersion 1.0.1
     * @apiDescription 附近店铺
     * @api {post} /shop.nearby_shop 附近店铺
     * @apiName Shop_nearby_shop
     * @apiParam {float} lng 经度
     * @apiParam {float} lat 纬度
     *
     * @apiSuccess {int} code 结果码
     * @apiSuccess {String} msg 消息说明
     * @apiSuccess {Object} data
     * @apiSuccess {int} data.id  店铺id
     * @apiSuccess {int} data.is_self 是否自营（0不是 1是）
     * @apiSuccess {String} data.shop_name 店铺名称
     * @apiSuccess {String} data.shop_keeper 店铺联系人店长
     * @apiSuccess {String} data.phone  店铺联系人电话
     * @apiSuccess {String} data.shop_phone 店铺电话
     * @apiSuccess {String} data.lng 经度
     * @apiSuccess {String} data.lat 纬度
     * @apiSuccess {String} data.address 店铺地址
     * @apiSuccess {int} data.add_time 店铺创建时间
     * @apiSuccess {String} data.logo 店铺logo
     * @apiSuccess {float} data.distance float  距离
     * @apiSuccessExample 成功示例
     *  HTTP/1.1 200 OK
     *  {
     *     code:200,
     *     msg:'success',
     *     data:{
     *         id:''
                ...
     *	   }
     *  }
     *
     *  @apiError code 0 系统异常错误
     *  @apiError msg token已经过期
     *  @apiErrorExample {json} 失败示例
     *  HTTP/1.1 404 Not Found
     *  {
     *     code:0,
     *      msg:'失败或没有数据返回',
     *   }
     */

    public static function nearby_shop($param){

        if (!isset($param['lng']) || empty($param['lng']) || !isset($param['lat']) || empty($param['lat'])){
            return ['data' => '', 'code' => 400001, 'msg' => '参数错误'];
        }
        try{
            $url = 'http://restapi.amap.com/v3/geocode/regeo?key='.config('map.webapi').'&location='.$param['lng'].','.$param['lat'].'&poitype=&radius=0&extensions=base&batch=false&roadlevel=0';
            $data = file_get_contents($url);
            $content=strip_tags($data);
            $content_arr=json_decode($content,true);
            $condition = [];
            if ($content_arr['infocode'] == '10000'){
                $condition['citycode'] = $content_arr['regeocode']['addressComponent']['citycode'];

            }
            $get_juli = 90000; // 距离米
            // 根据用户经纬度 获取附近店铺
            $coord = getAround($param['lat'], $param['lng'], $get_juli);
            $where = 'lat > ' . $coord[0] . ' AND lat < ' . $coord[1] . ' AND lng > ' . $coord[2] . ' AND lng < ' . $coord[3];
            $field = "id,is_self,shop_name,shop_keeper,phone,shop_phone,lng,lat,address,add_time,logo,". 'round((2 * 6378.137* asin(sqrt(pow(sin(pi()*(' . $param['lat'] . '-lat)/360),2)+cos(pi()*' .$param['lat'] .'/180)* cos(lat * pi()/180)*pow(sin(pi()*(' . $param['lng'] . '-lng)/360),2))))*1000) as distance';
            $shop_list = Db::table('yf_shop')->field($field)->where($where)->where($condition)->order('distance ASC')->limit(0, 50)->select();
            return ['data' =>$shop_list, 'code' => 200, 'msg' => 'success'];
        }catch (Exception $e){
            return ['data' =>'', 'code' => self::$err_code, 'msg' => $e->getMessage()];
        }
    }

    /**
     *
     * @apiGroup Shop
     * @apiVersion 2.0.0
     * @apiDescription 店铺首页信息（新）
     * @api {post} /shop.index 店铺首页信息(新)
     * @apiName Shop_index
     * @apiParam {int} shop_id 店铺id
     *
     * @apiSuccess {int} code 结果码
     * @apiSuccess {String} msg 消息说明
     * @apiSuccess {Object} data
     * @apiSuccess {Object} data.shop_info  店铺信息
     * @apiSuccess {int} data.shop_info.id  店铺id
     * @apiSuccess {int} data.shop_info.is_self  是否自营
     * @apiSuccess {String} data.shop_info.shop_name  店铺名称
     * @apiSuccess {String} data.shop_info.shop_keeper  店铺联系人店长
     * @apiSuccess {String} data.shop_info.phone  店铺联系人电话
     * @apiSuccess {String} data.shop_info.shop_phone  座机
     * @apiSuccess {float} data.shop_info.lng  经度
     * @apiSuccess {float} data.shop_info.lat  纬度
     * @apiSuccess {String} data.shop_info.address  店铺地址
     * @apiSuccess {int} data.shop_info.add_time  店铺创建时间
     * @apiSuccess {String} data.shop_info.province  所在省份
     * @apiSuccess {String} data.shop_info.city  所在城市名称
     * @apiSuccess {String} data.shop_info.citycode  城市代码
     * @apiSuccess {String} data.shop_info.logo  店铺logo
     * @apiSuccess {String} data.shop_info.share_url  店铺分享链接
     * @apiSuccess {Object} data.shop_info.logo_list  店铺图片列表
     * @apiSuccess {Object} data.category_list  店铺的商品类目
     * @apiSuccess {String} data.category_list.name 类目名称
     * @apiSuccess {int} data.category_list.id 类目id
     * @apiSuccess {Object} data.banner_one_list 顶部轮播
     * @apiSuccess {int} data.banner_one_list.carousel_id  轮播id
     * @apiSuccess {String} data.banner_one_list.title  标题
     * @apiSuccess {int} data.banner_one_list.cate  类型 1店铺 2网址链接 3专题 4单个商品
     * @apiSuccess {String} data.banner_one_list.item_content
     * @apiSuccess {String} data.banner_one_list.couponurl  cate=4时，才有用，其他类型没用
     * @apiSuccess {String} data.banner_one_list.image_url  封面图
     * @apiSuccess {Object} data.rq_recommend 人气推荐
     * @apiSuccess {String} data.rq_recommend.itemid  商品的淘宝/天猫id
     * @apiSuccess {String} data.rq_recommend.itemtitle  商品标题
     * @apiSuccess {String} data.rq_recommend.itemshorttitle  商品短标题
     * @apiSuccess {String} data.rq_recommend.itemprice 在售价
     * @apiSuccess {int} data.rq_recommend.itemsale  月销量
     * @apiSuccess {String} data.rq_recommend.itemendprice  券后价
     * @apiSuccess {String} data.rq_recommend.shoptype  店铺类型 B天猫 C淘宝
     * @apiSuccess {String} data.rq_recommend.couponurl  优惠券链接
     * @apiSuccess {String} data.rq_recommend.itempic  图片
     * @apiSuccess {String} data.rq_recommend.couponmoney  优惠券金额
     * @apiSuccess {String} data.rq_recommend.couponstarttime  优惠券开始时间
     * @apiSuccess {String} data.rq_recommend.couponendtime  优惠券结束时间
     * @apiSuccess {String} data.rq_recommend.share_url  分享链接
     * @apiSuccess {Object} data.banner_two_list 首页中部轮播
     * @apiSuccess {int} data.banner_two_list.carousel_id  轮播id
     * @apiSuccess {String} data.banner_two_list.title  标题
     * @apiSuccess {int} data.banner_two_list.cate  类型 1店铺 2网址链接 3专题 4单个商品
     * @apiSuccess {String} data.banner_two_list.item_content
     * @apiSuccess {String} data.banner_two_list.couponurl  cate=4时，才有用，其他类型没用
     * @apiSuccess {String} data.banner_two_list.image_url  封面图
     * @apiSuccess {Object} data.rq_recommend 人气推荐
     * @apiSuccess {int} data.rq_recommend.total 总条数
     * @apiSuccess {String} data.rq_recommend.per_page 每页条数
     * @apiSuccess {String} data.rq_recommend.current_page 当前页码
     * @apiSuccess {String} data.rq_recommend.last_page 下一页页码
     * @apiSuccess {Object} data.rq_recommend.data 数据列表
     * @apiSuccess {String} data.rq_recommend.data.id  商品id
     * @apiSuccess {String} data.rq_recommend.data.itemid  商品的淘宝/天猫id
     * @apiSuccess {String} data.rq_recommend.data.itemtitle  商品标题
     * @apiSuccess {String} data.rq_recommend.data.itemprice 在售价
     * @apiSuccess {int} data.rq_recommend.data.itemsale  月销量
     * @apiSuccess {String} data.rq_recommend.data.shoptype  店铺类型 B天猫 C淘宝
     * @apiSuccess {String} data.rq_recommend.data.itempic  图片
     * @apiSuccessExample 成功示例
     *  HTTP/1.1 200 OK
     *  {
     *     code:200,
     *     msg:'success',
     *     data:{
     *         category_list:''
    ...
     *	   }
     *  }
     *
     *  @apiError code 0 系统异常错误
     *  @apiError msg token已经过期
     *  @apiErrorExample {json} 失败示例
     *  HTTP/1.1 404 Not Found
     *  {
     *     code:0,
     *      msg:'失败或没有数据返回',
     *   }
     */
    public static function index($param){

        if (!isset($param['shop_id']) || empty($param['shop_id'])){
            return ['data' => '', 'code' => 400001, 'msg' => '参数错误'];
        }
        try{
            //店铺基本信息
            $info['shop_info'] = Db::table('yf_shop')->where(['id'=>$param['shop_id']])->find();
            if (!empty($info['shop_info'])){
                if (!empty($info['shop_info']['logo'])){
                        $logo_list = explode(',',$info['shop_info']['logo']);
                        foreach ($logo_list as $key=>$val){
                            if ($key==0){
                                $info['shop_info']['logo'] = get_img_url($val);
                            }
                            $logo_list[$key] = get_img_url($val);
                        }
                    $info['shop_info']['logo_list'] = $logo_list;
                }
                $info['shop_info']['share_url'] = '';
            }

            //附近店铺
            $shop_list = \app\api\common\Shop::nearby_shop(['lat'=>$info['shop_info']['lat'],'lng'=>$info['shop_info']['lng']]);
            if($shop_list['code'] == 200){
                if ($shop_list['data']){
                    foreach ($shop_list['data'] as $k=>$v){
                        $shop_list['data'][$k]['logo'] = get_img_url($v['logo']);
                    }
                }
                $info['shop_list'] = array_splice($shop_list['data'],1);;
            }else{
                self::$err_code = $shop_list['code'];
                throw new Exception($shop_list['msg']);
            }

            //商品类别
            $category_list = Db::table('yf_goods')->alias('a')->field('b.id,b.name')->join('yf_items_cate b','a.cat_id=b.id','LEFT')->where(['a.shop_id'=>$param['shop_id']])->group('cat_id')->select();
            if (!empty($category_list)){
                array_unshift($category_list,['id'=>0,'name'=>'推荐']);
            }
            $data['category_list'] = $category_list;

            //顶部banner
            $bannerone_list = \app\api\common\Common::banner(['position'=>4,'shop_id'=>$param['shop_id']]);
            if ($bannerone_list['code'] == 200){
                $info['banner_one_list'] = $bannerone_list['data'];
            }else{
                self::$err_code = $bannerone_list['code'];
                throw new Exception($bannerone_list['msg']);
            }

            //人气推荐
            $info['rq_recommend'] = Db::name('goods')->field('id,tb_id itemid,goods_name itemtitle,price itemprice,shoptype,original_img itempic,sales_sum itemsale')->where(['tuijian'=>1])->order('id desc')->limit(3)->select();

            //中部banner
            $bannertwo_list = \app\api\common\Common::banner(['position'=>5,'shop_id'=>$param['shop_id']]);
            if ($bannertwo_list['code'] == 200){
                $info['banner_two_list'] = $bannertwo_list['data'];
            }else{
                self::$err_code = $bannertwo_list['code'];
                throw new Exception($bannertwo_list['msg']);
            }

            //商品列表
            $goods = Db::name('goods')->field('id,tb_id itemid,goods_name itemtitle,price itemprice,shoptype,original_img itempic,sales_sum itemsale')->where(['is_on_sale'=>1])->order('id desc')->paginate('10');
            $info['goods'] = $goods->toArray();
            return ['data' =>$info, 'code' => 200, 'msg' => 'success'];
        }catch (Exception $e){
            return ['data' =>'', 'code' => self::$err_code, 'msg' => $e->getMessage()];
        }
    }


    /**
     *
     * @apiGroup Shop
     * @apiVersion 1.0.1
     * @apiDescription 店铺首页信息
     * @api {post} /shop.shop_index 店铺首页信息
     * @apiName Shop_shop_index
     * @apiParam {int} shop_id 店铺id
     *
     * @apiSuccess {int} code 结果码
     * @apiSuccess {String} msg 消息说明
     * @apiSuccess {Object} data
     * @apiSuccess {Object} data.shop_info  店铺信息
     * @apiSuccess {int} data.shop_info.id  店铺id
     * @apiSuccess {int} data.shop_info.is_self  是否自营
     * @apiSuccess {String} data.shop_info.shop_name  店铺名称
     * @apiSuccess {String} data.shop_info.shop_keeper  店铺联系人店长
     * @apiSuccess {String} data.shop_info.phone  店铺联系人电话
     * @apiSuccess {String} data.shop_info.shop_phone  座机
     * @apiSuccess {float} data.shop_info.lng  经度
     * @apiSuccess {float} data.shop_info.lat  纬度
     * @apiSuccess {String} data.shop_info.address  店铺地址
     * @apiSuccess {int} data.shop_info.add_time  店铺创建时间
     * @apiSuccess {String} data.shop_info.province  所在省份
     * @apiSuccess {String} data.shop_info.city  所在城市名称
     * @apiSuccess {String} data.shop_info.citycode  城市代码
     * @apiSuccess {String} data.shop_info.logo  店铺logo
     * @apiSuccess {Object} data.category_list  店铺的商品类目
     * @apiSuccess {String} data.category_list.name 类目名称
     * @apiSuccess {int} data.category_list.id 类目id
     * @apiSuccessExample 成功示例
     *  HTTP/1.1 200 OK
     *  {
     *     code:200,
     *     msg:'success',
     *     data:{
     *         category_list:''
                 ...
     *	   }
     *  }
     *
     *  @apiError code 0 系统异常错误
     *  @apiError msg token已经过期
     *  @apiErrorExample {json} 失败示例
     *  HTTP/1.1 404 Not Found
     *  {
     *     code:0,
     *      msg:'失败或没有数据返回',
     *   }
     */
    public static function shop_index($param){

        if (!isset($param['shop_id']) || empty($param['shop_id'])){
            return ['data' => '', 'code' => 400001, 'msg' => '参数错误'];
        }
        try{
            $data['shop_info'] = Db::table('yf_shop')->where(['id'=>$param['shop_id']])->find();
            if (!empty($data['shop_info'])){
                $data['shop_info']['logo'] = get_img_url($data['shop_info']['logo']);
            }
            $category_list = Db::table('yf_goods')->alias('a')->field('b.id,b.name')->join('yf_items_cate b','a.cat_id=b.id','LEFT')->where(['a.shop_id'=>$param['shop_id']])->group('cat_id')->select();
            if (!empty($category_list)){
                array_unshift($category_list,['id'=>0,'name'=>'全部']);
            }
            $data['category_list'] = $category_list;
            return ['data' =>$data, 'code' => 200, 'msg' => 'success'];
        }catch (Exception $e){
            return ['data' =>'', 'code' => self::$err_code, 'msg' => $e->getMessage()];
        }
    }

    /**
     *
     * @apiGroup Shop
     * @apiVersion 1.0.1
     * @apiDescription 店铺下的指定类目的商品
     * @api {post} /shop.shop_goods 店铺下的指定类目的商品
     * @apiName Shop_shop_goods
     * @apiParam {int} shop_id 店铺id
     * @apiParam {int} class_id 类目id
     * @apiParam {int} page 页码（data外）
     *
     * @apiSuccess {int} code 结果码
     * @apiSuccess {String} msg 消息说明
     * @apiSuccess {Object} data
     * @apiSuccess {int} data.id  商品id
     * @apiSuccess {String} data.goods_name 商品名称
     * @apiSuccess {String} data.price价格
     * @apiSuccess {String} data.original_img 商品图片
     * @apiSuccessExample 成功示例
     *  HTTP/1.1 200 OK
     *  {
     *     code:200,
     *     msg:'success',
     *     data:{
     *         id:''
    ...
     *	   }
     *  }
     *
     *  @apiError code 0 系统异常错误
     *  @apiError msg token已经过期
     *  @apiErrorExample {json} 失败示例
     *  HTTP/1.1 404 Not Found
     *  {
     *     code:0,
     *      msg:'失败或没有数据返回',
     *   }
     */
    public static function shop_goods($param){

        if (!isset($param['shop_id']) || empty($param['shop_id']) || !isset($param['class_id'])){
            return ['data' => '', 'code' => 400001, 'msg' => '参数错误'];
        }
        try{
            if ($param['class_id'] == 0){
                $goods_list = Db::table('yf_goods')->field('id,tb_id,goods_name,price,original_img,shoptype')->where(['shop_id'=>$param['shop_id'],'store_count'=>['neq',0]])->order('id desc')->paginate('10');
            }else{
                $goods_list = Db::table('yf_goods')->field('id,tb_id,goods_name,price,original_img,shoptype')->where(['shop_id'=>$param['shop_id'],'cat_id'=>$param['class_id'],'store_count'=>['neq',0]])->order('id desc')->paginate('10');
            }
            $goods_list = $goods_list->toArray();
            if (!empty($goods_list['data'])){
                foreach ($goods_list['data'] as $k=>$v){
                    $goods_list['data'][$k]['share_url'] = '';
                }
            }
            return ['data' =>$goods_list, 'code' => 200, 'msg' => 'success'];
        }catch (Exception $e){
            return ['data' =>'', 'code' => self::$err_code, 'msg' => $e->getMessage()];
        }
    }

    /**
     *
     * @apiGroup Shop
     * @apiVersion 2.0.0
     * @apiDescription 店铺下的指定类目的商品(新)
     * @api {post} /shop.goods 店铺下的指定类目的商品(新)
     * @apiName Shop_goods
     * @apiParam {int} shop_id 店铺id
     * @apiParam {int} class_id 类目id
     * @apiParam {int} page 页码（data外）
     *
     * @apiSuccess {int} code 结果码
     * @apiSuccess {String} msg 消息说明
     * @apiSuccess {Object} data
     * @apiSuccess {int} data.total 总条数
     * @apiSuccess {String} data.per_page 每页条数
     * @apiSuccess {String} data.current_page 当前页码
     * @apiSuccess {String} data.last_page 下一页页码
     * @apiSuccess {Object} data.data 数据列表
     * @apiSuccess {int} data.data.id  商品id
     * @apiSuccess {String} data.data.itemid  商品id
     * @apiSuccess {String} data.data.itemtitle 商品名称
     * @apiSuccess {String} data.data.itemprice 价格
     * @apiSuccess {String} data.data.shoptype C为淘宝 B为天猫
     * @apiSuccess {String} data.data.itempic 商品图片
     * @apiSuccess {int} data.data.itemsale 销量
     * @apiSuccessExample 成功示例
     *  HTTP/1.1 200 OK
     *  {
     *     code:200,
     *     msg:'success',
     *     data:{
     *         id:''
    ...
     *	   }
     *  }
     *
     *  @apiError code 0 系统异常错误
     *  @apiError msg token已经过期
     *  @apiErrorExample {json} 失败示例
     *  HTTP/1.1 404 Not Found
     *  {
     *     code:0,
     *      msg:'失败或没有数据返回',
     *   }
     */
    public static function goods($param){

        if (!isset($param['shop_id']) || empty($param['shop_id']) || !isset($param['class_id'])){
            return ['data' => '', 'code' => 400001, 'msg' => '参数错误'];
        }
        try{
            if ($param['class_id'] == 0){
                $goods_list = Db::table('yf_goods')->field('id,tb_id itemid,goods_name itemtitle,price itemprice,shoptype,original_img itempic,sales_sum itemsale')->where(['shop_id'=>$param['shop_id'],'is_on_sale'=>1,'store_count'=>['neq',0]])->order('id desc')->paginate('10');
            }else{
                $goods_list = Db::table('yf_goods')->field('id,tb_id itemid,goods_name itemtitle,price itemprice,shoptype,original_img itempic,sales_sum itemsale')->where(['shop_id'=>$param['shop_id'],'cat_id'=>$param['class_id'],'is_on_sale'=>1,'store_count'=>['neq',0]])->order('id desc')->paginate('10');
            }
            $goods_list = $goods_list->toArray();
            return ['data' =>$goods_list, 'code' => 200, 'msg' => 'success'];
        }catch (Exception $e){
            return ['data' =>'', 'code' => self::$err_code, 'msg' => $e->getMessage()];
        }
    }

    /**
     *
     * @apiGroup Shop
     * @apiVersion 2.0.0
     * @apiDescription 店铺人气推荐的商品
     * @api {post} /shop.shop_recommend 店铺推荐的商品
     * @apiName Shop_shop_recommend
     * @apiParam {int} shop_id 店铺id
     * @apiParam {int} page 页码（data外）
     *
     * @apiSuccess {int} code 结果码
     * @apiSuccess {String} msg 消息说明
     * @apiSuccess {Object} data
     * @apiSuccess {int} data.total 总条数
     * @apiSuccess {String} data.per_page 每页条数
     * @apiSuccess {String} data.current_page 当前页码
     * @apiSuccess {String} data.last_page 下一页页码
     * @apiSuccess {Object} data.data 数据列表
     * @apiSuccess {int} data.data.id  商品id
     * @apiSuccess {String} data.data.itemid  商品id
     * @apiSuccess {String} data.data.itemtitle 商品名称
     * @apiSuccess {String} data.data.itemprice 价格
     * @apiSuccess {String} data.data.shoptype C为淘宝 B为天猫
     * @apiSuccess {String} data.data.itempic 商品图片
     * @apiSuccess {int} data.data.itemsale 销量
     * @apiSuccessExample 成功示例
     *  HTTP/1.1 200 OK
     *  {
     *     code:200,
     *     msg:'success',
     *     data:{
     *         id:''
    ...
     *	   }
     *  }
     *
     *  @apiError code 0 系统异常错误
     *  @apiError msg token已经过期
     *  @apiErrorExample {json} 失败示例
     *  HTTP/1.1 404 Not Found
     *  {
     *     code:0,
     *      msg:'失败或没有数据返回',
     *   }
     */
    public static function shop_recommend($param){

        if (!isset($param['shop_id']) || empty($param['shop_id'])){
            return ['data' => '', 'code' => 400001, 'msg' => '参数错误'];
        }
        try{

            $goods_list = Db::table('yf_goods')
                ->field('id,tb_id itemid,goods_name itemtitle,price itemprice,shoptype,original_img itempic,sales_sum itemsale')
                ->where(['shop_id'=>$param['shop_id'],'tuijian'=>1,'is_on_sale'=>1,'store_count'=>['neq',0]])
                ->order('id desc')
                ->paginate('10');
            $goods_list = $goods_list->toArray();
            return ['data' =>$goods_list, 'code' => 200, 'msg' => 'success'];
        }catch (Exception $e){
            return ['data' =>'', 'code' => self::$err_code, 'msg' => $e->getMessage()];
        }
    }

    /**
     *
     * @apiGroup Shop
     * @apiVersion 2.0.0
     * @apiDescription 店铺商品搜索
     * @api {post} /shop.goods_search 店铺商品搜索
     * @apiName Shop_goods_search
     * @apiParam {int} shop_id 店铺id
     * @apiParam {String} keyword 关键词
     * @apiParam {int} page 页码（data外）
     *
     * @apiSuccess {int} code 结果码
     * @apiSuccess {String} msg 消息说明
     * @apiSuccess {Object} data
     * @apiSuccess {int} data.total 总条数
     * @apiSuccess {String} data.per_page 每页条数
     * @apiSuccess {String} data.current_page 当前页码
     * @apiSuccess {String} data.last_page 下一页页码
     * @apiSuccess {Object} data.data 数据列表
     * @apiSuccess {int} data.data.id  商品id
     * @apiSuccess {String} data.data.itemid  商品id
     * @apiSuccess {String} data.data.itemtitle 商品名称
     * @apiSuccess {String} data.data.itemprice 价格
     * @apiSuccess {String} data.data.shoptype C为淘宝 B为天猫
     * @apiSuccess {String} data.data.itempic 商品图片
     * @apiSuccess {int} data.data.itemsale 销量
     * @apiSuccessExample 成功示例
     *  HTTP/1.1 200 OK
     *  {
     *     code:200,
     *     msg:'success',
     *     data:{
     *         id:''
    ...
     *	   }
     *  }
     *
     *  @apiError code 0 系统异常错误
     *  @apiError msg token已经过期
     *  @apiErrorExample {json} 失败示例
     *  HTTP/1.1 404 Not Found
     *  {
     *     code:0,
     *      msg:'失败或没有数据返回',
     *   }
     */
    public static function goods_search($param){

        if (!isset($param['shop_id']) || empty($param['shop_id']) || !isset($param['keyword']) || empty($param['keyword'])){
            return ['data' => '', 'code' => 400001, 'msg' => '参数错误'];
        }
        try{
            $goods_list = Db::table('yf_goods')
                ->field('id,tb_id itemid,goods_name itemtitle,price itemprice,shoptype,original_img itempic,sales_sum itemsale')
                ->where(['shop_id'=>$param['shop_id'],'goods_name'=>['like','%'.$param['keyword'].'%'],'is_on_sale'=>1,'store_count'=>['neq',0]])
                ->order('id desc')
                ->paginate('10');
            $goods_list = $goods_list->toArray();
            return ['data' =>$goods_list, 'code' => 200, 'msg' => 'success'];
        }catch (Exception $e){
            return ['data' =>'', 'code' => self::$err_code, 'msg' => $e->getMessage()];
        }
    }

}